var gl_vue_vm_list_html = $('#vue_vm_list').html();

$(function() {
    $('#vue_vm_list div').hide();
});

function findSubjectRoomSummaryList() {
    if($('#vue_vm_list div').length==0) {return;}
    $('#vue_vm_list div').hide();

    var startYear = $('#startYear').val();
    var startMonth = $('#startMonth').val();
    var startDay = $('#startDay').val();
    var endYear = $('#endYear').val();
    var endMonth = $('#endMonth').val();
    var endDay = $('#endDay').val();
    var startTime = getStandardDay(startYear, startMonth, startDay);
    var endTime = getStandardDay(endYear, endMonth, endDay);

    if(isEmpty(startYear)) {
        alert('请输入开始年');
        return;
    }
    if(isEmpty(startMonth)) {
        alert('请选择开始月');
        return;
    }
    if(isEmpty(startDay)) {
        alert('请选择开始日');
        return;
    }
    if(isEmpty(endYear)) {
        alert('请输入结束年');
        return;
    }
    if(isEmpty(endMonth)) {
        alert('请选择结束月');
        return;
    }
    if(isEmpty(endDay)) {
        alert('请选择结束日');
        return;
    }
    if(isEmpty(startTime)) {
        alert('请输入开始时间');
        return;
    }
    if(isEmpty(endTime)) {
        alert('请输入结束时间');
        return;
    }
    find_basic_by_json(path+'/elderPayRecord/findSubjectRoomSummaryList', {dateSince: startTime, dateEnd:endTime,paperType:5},
        onSuccess=function(response) {
            $('#vue_vm_list').html(gl_vue_vm_list_html);
            new Vue({
                el: '#vue_vm_list',
                data: {
                    todos: response.data
                },
                methods: {
                    getPrintDate:function() {
                        return startTime+"至"+endTime;
                    },
                    materialCostTotal(parent){
                        var cost = 0;
                        for(var i=0;i<parent.subjectRoomSummaryItems.length;i++){
                            cost+=parent.subjectRoomSummaryItems[i].materialCost
                        }
                        return cost;
                    },
                    bedCostTotal(parent){
                        var cost = 0;
                        for(var i=0;i<parent.subjectRoomSummaryItems.length;i++){
                            cost+=parent.subjectRoomSummaryItems[i].bedCost
                        }
                        return cost;
                    },
                    nursingCostTotal(parent){
                        var cost = 0;
                        for(var i=0;i<parent.subjectRoomSummaryItems.length;i++){
                            cost+=parent.subjectRoomSummaryItems[i].nursingCost
                        }
                        return cost;
                    },
                    waterCostTotal(parent){
                        var cost = 0;
                        for(var i=0;i<parent.subjectRoomSummaryItems.length;i++){
                            cost+=parent.subjectRoomSummaryItems[i].waterCost
                        }
                        return cost;
                    },
                    eleCostTotal(parent){
                        var cost = 0;
                        for(var i=0;i<parent.subjectRoomSummaryItems.length;i++){
                            cost+=parent.subjectRoomSummaryItems[i].eleCost
                        }
                        return cost;
                    },
                    hotWaterCostTotal(parent){
                        var cost = 0;
                        for(var i=0;i<parent.subjectRoomSummaryItems.length;i++){
                            cost+=parent.subjectRoomSummaryItems[i].hotWaterCost
                        }
                        return cost;
                    },
                    handCostTotal(parent){
                        var cost = 0;
                        for(var i=0;i<parent.subjectRoomSummaryItems.length;i++){
                            cost+=parent.subjectRoomSummaryItems[i].handCost
                        }
                        return cost;
                    },
                    getTotal(){
                        var totalCost = 0;
                        for(var i=0;i<this.todos.length;i++){
                            let parent = this.todos[i];
                            totalCost+=this.materialCostTotal(parent)+this.bedCostTotal(parent)+this.nursingCostTotal(parent)+this.waterCostTotal(parent)+
                                this.eleCostTotal(parent)+this.hotWaterCostTotal(parent)+this.handCostTotal(parent);
                        }
                        return totalCost;
                    }
                }
            });
            $('#vue_vm_list div').show();
        },
        onEmpty=function(response) {
            alert("暂无数据");
            $('#vue_vm_list').html(gl_vue_vm_list_html);
            new Vue({
                el: '#vue_vm_list',
                data: {
                    todos: response.data
                },
                methods: {
                    getPrintDate:function() {
                        return startTime+"至"+endTime;
                    },
                }
            });

            $('#vue_vm_list div').show();
        }
    );
}
